package us.icitap.commandcenter.utils;

import java.util.Date;
import java.util.List;

import us.icitap.commandcenter.CommandCenterUI;
import us.icitap.commandcenter.business.ejb.persistence.CallReason;
import us.icitap.commandcenter.business.ejb.persistence.CommandCenter;
import us.icitap.commandcenter.business.ejb.persistence.Grade;
import us.icitap.commandcenter.business.ejb.persistence.PoliceAction;

public class ProjectLists {

	private static  List<CallReason> callReasonList;
	private static  Date callReasonDate;
	
	@SuppressWarnings("unchecked")
	public static  List<CallReason> getCallReasonList(boolean freshData) {
		Date now = new Date();
		if (callReasonList == null || callReasonDate == null || freshData){
			callReasonList =  CommandCenterUI.appStatelessBean.getCallPersistBean().getList(CallReason.class, true, null).getObject();
			
			callReasonDate = now;
			
		}
		int difHours = (int)((now.getTime() - callReasonDate.getTime()) / (1000*60*60));
		if (difHours > 24){
			callReasonList =  CommandCenterUI.appStatelessBean.getCallPersistBean().getList(CallReason.class, true, null).getObject();
			callReasonDate = now;
			
		}
		
		return callReasonList;
	}
	
	
	private static  List<Grade> gradeList;
	private static  Date gradeDate;
	
	@SuppressWarnings("unchecked")
	public static  List<Grade> getGradeList() {
		Date now = new Date();
		if (gradeList == null || gradeDate == null){
			gradeList =  CommandCenterUI.appStatelessBean.getCallPersistBean().getList(Grade.class, true, null).getObject();
			
			gradeDate = now;
			
		}
		int difHours = (int)((now.getTime() - gradeDate.getTime()) / (1000*60*60));
		if (difHours > 24){
			gradeList =  CommandCenterUI.appStatelessBean.getCallPersistBean().getList(Grade.class, true, null).getObject();
			gradeDate = now;
			
		}
		
		return gradeList;
	}
	
	
	
	
	
	
	private static  List<CommandCenter> ccList;
	private static  Date ccDate;
	
	@SuppressWarnings("unchecked")
	public static  List<CommandCenter> getCcList(boolean freshData) {
		Date now = new Date();
		if (ccList == null || ccDate == null || freshData){
			ccList =  CommandCenterUI.appStatelessBean.getCallPersistBean().getList(CommandCenter.class, true, "o.name").getObject();
			ccDate = now;
			
		}
		int difHours = (int)((now.getTime() - ccDate.getTime()) / (1000*60*60));
		if (difHours > 24){
			ccList =   CommandCenterUI.appStatelessBean.getCallPersistBean().getList(CommandCenter.class, true, "o.name").getObject();
			ccDate = now;
			
		}
		
		return ccList;
	}
	
	private static  List<PoliceAction> policeActionList;
	private static  Date policeActionDate;
	
	@SuppressWarnings("unchecked")
	public static  List<PoliceAction> getPoliceActionList() {
		Date now = new Date();
		if (policeActionList == null || policeActionDate == null){
			policeActionList =  CommandCenterUI.appStatelessBean.getCallPersistBean().getList(PoliceAction.class, true, null).getObject();
			
			policeActionDate = now;
			
		}
		int difHours = (int)((now.getTime() - policeActionDate.getTime()) / (1000*60*60));
		if (difHours > 24){
			policeActionList =   CommandCenterUI.appStatelessBean.getCallPersistBean().getList(PoliceAction.class, true, null).getObject();
			policeActionDate = now;
			
		}
		
		return policeActionList;
	}
	
}
